Writing
a dialog based application which accepts drag and drop
A programming
tutorial by Lim, Chooi Guan
Preface
This
tutorial is for developers who are interested in implementing drag and drop for
their applications. I implement drag and
drop mainly for fully automation purposes rather than just regular opening of
files, but it is up to you to decide how you wish to handle it.
Instructions
·
//{{AFX_MSG(blahDlg)
afx_msg void
OnDropFiles( HDROP hDropInfo ); //for drag and drop
//}}AFX_MSG
·
BEGIN_MESSAGE_MAP(blahDlg,
CDialog)
ON_WM_DROPFILES() // drag and drop message map entry
END_MESSAGE_MAP()
·
afx_msg void blahDlg::OnDropFiles(
HDROP hDropInfo ) {
// following message is shown when an object is dropped
AfxMessageBox(“This
is an example of drag and drop”);
}
You have
now successfully implemented the drag and drop function. To extract information
from the HDROP structure, use the following function;
DragQueryFile() – Queries the
HDROPINFO structure
For
example, to get the number of items dropped, you would use the following
statement;
int iObjectCount =
DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,NULL);
Look up http://msdn.microsoft.com or the MSDN
CDROM library for more information on the drag and drop query function.
That
concludes this tutorial. Now set forth
and implement drag and drop in your applications!